package com.gitee.wsl.mathematics.matrix.ext

import com.gitee.wsl.mathematics.matrix.Matrix
import com.gitee.wsl.mathematics.vector.Vector

internal val Matrix<*, *, *>.NotSquareException
    get() = UnsupportedOperationException("$rowCount * $colCount is not a square")


internal val NotFullRankException
    get() = UnsupportedOperationException("matrix is not full-rank, so some operation is invalid")

// 断言矩阵是方阵
internal fun<T:Number>  Matrix<T, *, *>.assertSquare() {
    if (!isSquare) throw NotSquareException
}

// 断言矩阵能乘向量
internal fun<T:Number> assertCanMultiply(a: Matrix<T, *, *>, b: Vector<T, *>) {
    if (a.colCount != b.dim)
        throw UnsupportedOperationException("matrix of ${a.rowCount}*${a.colCount} and ${b.dim}*1 is not match to multiply")
}


// 断言矩阵能乘向量
internal fun<T:Number> assertCanMultiply(a: Matrix<T, *, *>, b: Matrix<T, *, *>) {
    if (a.colCount != b.rowCount)
        throw UnsupportedOperationException("matrix of ${a.rowCount}*${a.colCount} and ${b.colCount}*1 is not match to multiply")
}